﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;

public partial class admin_qlconsulting : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "this.originalstyle=this.style.backgroundColor;this.style.backgroundColor='#99ffcc'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.originalstyle;");
        }
    }

    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        e.Cancel = true;
        Label id = (Label)this.GridView1.Rows[e.NewEditIndex].Cells[0].FindControl("id");
        //Response.Write(id.Text);
        Response.Redirect("Default.aspx?page=edconsulting&id=" + id.Text);
    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.CompareTo("addLang") == 0)
        {
            int index = Convert.ToInt32(e.CommandArgument);
            GridViewRow row = GridView1.Rows[index];
            Label id = (Label)row.FindControl("id");
            Response.Redirect("Default.aspx?page=qlconsultinglang&id=" + id.Text);
        }
        if (e.CommandName.CompareTo("det") == 0)
        {
            int index = Convert.ToInt32(e.CommandArgument);
            GridViewRow row = GridView1.Rows[index];
            Label id = (Label)row.FindControl("id");
            Response.Redirect("Default.aspx?page=qlconsultingdetail&id=" + id.Text);
        }
    }

    protected void addbt_Click(object sender, EventArgs e)
    {
        connection con = new connection();
        SqlConnection cn = con.connect();
        SqlCommand mySqlSelect = new SqlCommand("insert into consulting values(@id,@des)", cn);
        mySqlSelect.CommandType = CommandType.Text;

        SqlParameter desc = new SqlParameter("@des", SqlDbType.NVarChar, 100);
        desc.Value = des.Text;

        SqlParameter id = new SqlParameter("@id", SqlDbType.BigInt);
        Double idt = Common.ToSeconds(DateTime.Now);
        id.Value = idt;

        mySqlSelect.Parameters.Add(desc);
        mySqlSelect.Parameters.Add(id);
        mySqlSelect.ExecuteNonQuery();
        cn.Close();
        SqlDataSource1.DataBind();
        GridView1.DataBind();
    }

    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        e.Cancel = true;
        Label id = (Label)this.GridView1.Rows[e.RowIndex].Cells[0].FindControl("id");
        connection con = new connection();
        SqlConnection cn = con.connect();
        //xoa ben bang consulting_lang
        SqlCommand mySqlSelect = new SqlCommand("delete from consulting_lang where id = @id", cn);
        mySqlSelect.CommandType = CommandType.Text;

        SqlParameter idt = new SqlParameter("@id", SqlDbType.BigInt);
        idt.Value = Int64.Parse(id.Text);

        mySqlSelect.Parameters.Add(idt);
        mySqlSelect.ExecuteNonQuery();
        //xoa ben bang consultingdetails_lang
        SqlCommand mySqlSelect3 = new SqlCommand("delete from consultingDetails_lang where id = @idtt", cn);
        mySqlSelect3.CommandType = CommandType.Text;

        SqlParameter id3 = new SqlParameter("@idtt", SqlDbType.BigInt);
        id3.Value = Int64.Parse(id.Text);

        mySqlSelect3.Parameters.Add(id3);
        mySqlSelect3.ExecuteNonQuery();
        //xoa ben bang consultingdetails
        SqlCommand mySqlSelect2 = new SqlCommand("delete from consultingDetails where id = @idtt", cn);
        mySqlSelect2.CommandType = CommandType.Text;

        SqlParameter id2 = new SqlParameter("@idtt", SqlDbType.BigInt);
        id2.Value = Int64.Parse(id.Text);

        mySqlSelect2.Parameters.Add(id2);
        mySqlSelect2.ExecuteNonQuery();
        
        //xoa ben bang consulting
        SqlCommand mySqlSelect1 = new SqlCommand("delete from consulting where id = @idtt", cn);
        mySqlSelect1.CommandType = CommandType.Text;

        SqlParameter idtt = new SqlParameter("@idtt", SqlDbType.BigInt);
        idtt.Value = Int64.Parse(id.Text);

        mySqlSelect1.Parameters.Add(idtt);
        mySqlSelect1.ExecuteNonQuery(); 

        cn.Close();
        SqlDataSource1.DataBind();
        GridView1.DataBind();
    }
}